/* 
 * File:   main.cpp
 * Author: Yinhaochuan
 *
 * Created on 2013年10月5日, 下午8:28
 */

//#include <cstdlib>
#include <stdio.h>
//using namespace std;
const int NO_REPEAT_FLAG = -1;
void swap(int &a,int &b)
{ 
    if(a!=b)
    {
        a=a^b;
        b=a^b;
        a=a^b;
    }
}

int RadixSort(int a[], int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        while(i!=a[i])
        {
            if(a[i]==a[a[i]])
                return a[i];
            swap(a[i],a[a[i]]);
        }
    }
    return NO_REPEAT_FLAG;
}

void PrintArray(int a[],int n)
{
    for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    putchar('\n');
}
/*
 * 
 */
int main(int argc, char** argv) {
    const int MAXN = 10;
    int a[MAXN] = {2,4,1,5,7,6,1,9,0,2};
    
    printf("The array is :\n");
    PrintArray(a,MAXN);
    
    int nRepeatNumber = RadixSort(a,MAXN);
    if(nRepeatNumber!=NO_REPEAT_FLAG)
        printf("There exsit repeat number, and the number is %d\n",nRepeatNumber);
    else
        printf("There exsit no repeat number\n");
    return 0;
}

